const CompressionWebpackPlugin = require('compression-webpack-plugin');

module.exports = {
    productionSourceMap: true,
    transpileDependencies: ['element-ui'],  // 需要兼容IE10要放开这个
    chainWebpack: config => {
        config.plugin('html').tap(options => {
            options[0].title = '智慧校园v1.0.0';
            return options;
        });
        if (process.env.NODE_ENV === 'production') {
            config.plugin('compressionPlugin').use(new CompressionWebpackPlugin({
                test: /\.(js|css|less)$/,
                threshold: 10240,  // 对超过10kb的文件压缩
                deleteOriginalAssets: false
            }));
        }
    },
    configureWebpack: config => {
        if (process.env.NODE_ENV !== 'production') { // development
            config.devtool = 'source-map'
        }
    },
    devServer: {
        proxy: {
            "/api": {
                target: "http://localhost:8080/", // 这里是后台api域名地址
                pathRewrite: {'^/api' : '/api'}, // 去除/api前缀
                changeOrigin: true, // 跨域
                cookieDomainRewrite: "localhost", // 这里是后台api域名地址
                cookiePathRewrite: "/",
            }
        }
    }
}